import collections
class Solution(object):
    def topKFrequent(self, words, k):
        """
        :type words: List[str]
        :type k: int
        :rtype: List[str]
        """
        d = collections.Counter(words)
        c = [[-d[key], key] for key in d]
        c.sort()
        return [c[i][1] for i in range(k)]


data = Solution()
words = ["i", "love", "leetcode", "i", "love", "coding"]
k = 2
print(data.topKFrequent(words, k))
